# -*- coding: utf-8 -*-
from django.db import models

class Host(models.Model):
    """ 主机和最新的数据记录 """
    ip = models.GenericIPAddressField(null=True, blank=True);
    mem = models.CharField(max_length = 50,null=True, blank=True);
    mem_use = models.CharField(max_length = 50,null=True, blank=True);
    disk = models.CharField(max_length = 50,null=True, blank=True);
    disk_use = models.CharField(max_length = 50,null=True, blank=True);
    cpu_use = models.CharField(max_length = 50,null=True, blank=True);
    update_time = models.DateTimeField(auto_now_add=True,null=True, blank=True);
    area = models.CharField(max_length = 50,null=True, blank=True);
    model = models.CharField(max_length = 50,null=True, blank=True);
    carea = models.CharField(max_length = 50,null=True, blank=True);
    patrol_time = models.DateTimeField(null=True, blank=True);
    os_type = models.CharField(max_length = 50,null=True, blank=True);
    bk_cloud_id = models.IntegerField(null=True, blank=True);
    
    def __unicode__(self):
        return self.ip;
    class Meta:
        ordering = ['update_time'];

class BkCloud(models.Model):
    host = models.ForeignKey(Host);
    bk_obj_name = models.CharField(max_length = 50,null=True, blank=True);
    bk_obj_id = models.CharField(max_length = 50,null=True, blank=True);
    bk_obj_icon = models.CharField(max_length = 50,null=True, blank=True);
    bk_inst_id = models.IntegerField(null=True, blank=True);
    bk_inst_name = models.CharField(max_length = 50,null=True, blank=True);
    
    
class Biz(models.Model):
    host = models.ForeignKey(Host)
    bz_id = models.CharField(max_length = 50,null=True, blank=True);
    bz_name = models.CharField(max_length = 50,null=True, blank=True);
    
    def __unicode__(self):
        return self.bz_name;
            
class MemDiskCpuHis(models.Model):
    """ 内存磁盘cpu指标历史记录 """
    
    host = models.ForeignKey(Host);
    mem_use = models.CharField(max_length = 50,null=True, blank=True);
    disk_use = models.CharField(max_length = 50,null=True, blank=True);
    cpu_use = models.CharField(max_length = 50,null=True, blank=True);
    job_time = models.DateTimeField(auto_now_add=True,null=True, blank=True);
    update_time = models.DateTimeField(auto_now_add=True,null=True, blank=True);
    seq = models.CharField(max_length = 200, null=True, blank=True);
    log_time = models.CharField(max_length = 20, null=True, blank=True);
    state = models.BooleanField();
    
    def __unicode__(self):
        return self.mem+"/"+self.disk+"/"+self.cpu;
    class Meta:
        ordering = ['update_time'];
